package stock;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import stock.model.LTModel;
import stock.model.SBStock;
import stock.testSB.SB1;
import stock.testSB.Stock1;

@Component
public class MyApplicationRunner implements ApplicationRunner {
	@Override
	public void run(ApplicationArguments args) throws Exception {
		// 这里编写启动完成后要执行的代码
		System.out.println("Spring Boot应用启动完成，ApplicationRunner执行");

		Session session1 = ContextUtil.getSessionFactory1().openSession();

		List<LTModel> list = new ArrayList<LTModel>();

		list = session1.createQuery("from LTModel t ").list();

		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				Stock1 stock1 = new Stock1();
				stock1.setName(list.get(i).getCode1()); 
				SB1.listall.add(stock1);
			}
		}
		session1.close();
		System.out.println("加载sb1.listall长度为：" + SB1.listall.size());

	}
}
